﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Lxts : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler {
    private GameObject root=null;
    private GameObject lx_line=null;
    private GameObject lx_yj1=null;
    private GameObject lx_yj2 = null;
    private bool is_tishi = false;

    private float timer = 0.5f;
    private bool isShow = true;//用来控制闪烁的内容
    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        if (is_tishi == true)
        {
            Shan(lx_line,lx_yj1,lx_yj2);
        }
	}

    //鼠标进入，退出提示
    public void OnPointerEnter(PointerEventData eventData)
    {
        if (Init.shanIndex<5&&this.name == Init.LineMap[Init.shanIndex][3])
        {
            //Debug.Log("进入"+this.name);
            is_tishi = true;
            root = GameObject.Find("line");
            //提示线
            lx_line = root.transform.Find(Init.LineMap[Init.shanIndex][2]).gameObject;
            lx_line.SetActive(true);
            //提示元件
            if (GameObject.Find(Init.LineMap[Init.shanIndex][0]))
            {
                lx_yj1 = GameObject.Find(Init.LineMap[Init.shanIndex][0]);
            }
            if (GameObject.Find(Init.LineMap[Init.shanIndex][1]))
            {
                lx_yj2 = GameObject.Find(Init.LineMap[Init.shanIndex][1]);
            }           
        }
        
    }

    public void OnPointerExit(PointerEventData eventData)
    {

        if (Init.shanIndex<5&&this.name == Init.LineMap[Init.shanIndex][3])
        {
           //Debug.Log("退出"+this.name);
           is_tishi = false;
            //lx_line = root.transform.Find(Init.LineMap[Init.shanIndex][2]).gameObject;
           lx_line.SetActive(false);
            if (lx_yj1)
            {
                lx_yj1.GetComponent<MeshRenderer>().material.color = Color.red;
            }
            if (lx_yj2)
            {
                lx_yj2.GetComponent<MeshRenderer>().material.color = Color.red;
            }
           
        }
        
    }

    //元件提示连线顺序,闪烁
    void Shan(GameObject ts1,GameObject ts2,GameObject ts3)
    {
        timer -= Time.deltaTime;
        if (timer < 0 && timer > -0.5f)
        {
            isShow = false;
        }
        else if (timer <= -0.5f)
        {
            timer = 0.5f;
            isShow = true;
        }

        if (isShow)
        {
            ts1.SetActive(true);                           
            if (ts2)
            {
              ts2.GetComponent<MeshRenderer>().material.color=Color.red;
            }
            if (ts3)
            {
            ts3.GetComponent<MeshRenderer>().material.color = Color.red; 
            }
            
        }
        else
        {
            ts1.SetActive(false);
            if (ts2)
            {
                ts2.GetComponent<MeshRenderer>().material.color = Color.yellow;
            }
            if (ts3)
            {
                ts3.GetComponent<MeshRenderer>().material.color = Color.yellow;
            }
        }
    }
}
